home *** CD-ROM | disk | FTP | other *** search
- /*
- File: TransferProvider.c
-
- Contains: Sample that shows how to use OTTransferProviderOwnership.
-
- Written by: Quinn "The Eskimo!"
-
- Copyright: Copyright © 1997-1999 by Apple Computer, Inc., All Rights Reserved.
-
- You may incorporate this Apple sample source code into your program(s) without
- restriction. This Apple sample source code has been provided "AS IS" and the
- responsibility for its operation is yours. You are not permitted to redistribute
- this Apple sample source code as "Apple sample source code" after having made
- changes. If you're going to re-distribute the source, we require that you make
- it clear in the source that the code was descended from Apple sample source
- code, but that you've made changes.
-
- Change History (most recent first):
- 7/23/1999 Karl Groethe Updated for Metrowerks Codewarror Pro 2.1
-
-
- */
-
- ////////////////////////////////////////////////////////////
- // Pick up general Open Transport stuff.
-
- #include <OpenTransport.h>
-
- ////////////////////////////////////////////////////////////
- // Pick up OT debugging macros.
-
- #include <OTDebug.h>
-
- ////////////////////////////////////////////////////////////
- // Pick up standard C libraries.
-
- #include <stdio.h>
-
- ////////////////////////////////////////////////////////////
- // Get prototypes for the factory.
-
- #include "ProviderFactory.h"
-
- ////////////////////////////////////////////////////////////
- // OTDebugStr is not defined in any of the interfaces,
- // but it is in the libraries.
-
- extern void OTDebugStr(char *str);
-
- ////////////////////////////////////////////////////////////
-
- static OSStatus GetProviderFromFactory(void)
- // This routine calls FactoryCreateEndpoint to
- // create an endpoint that is owned by the provider
- // factory, and then uses OTTransferProviderOwnership
- // to let Open Transport know that the newly created
- // endpoint is owned by us. It then does a simple
- // operation an the endpoint, just to make sure
- // everything works OK.
- {
- OSStatus err;
- EndpointRef originalEndpoint;
- OTClient originalOwner;
- EndpointRef newEndpoint;
- TEndpointInfo newEndpointInfo;
-
- // Use the factory library to create an endpoint.
-
- err = FactoryCreateEndpoint(&originalEndpoint, &originalOwner);
-
- if (err == noErr) {
-
- // Transfer the ownership of that endpoint, so that OT knows
- // we now own it.
-
- newEndpoint = OTTransferProviderOwnership(originalEndpoint, originalOwner, &err);
-
- if (err == noErr) {
-
- // We can now use newEndpoint as if we created it. We call
- // OTGetEndpointInfo as an example of an operation on the
- // endpoint.
-
- err = OTGetEndpointInfo(newEndpoint, &newEndpointInfo);
-
- if (err == noErr) {
- printf("Maximum size of endpoint address = %ld.\n", newEndpointInfo.addr);
- }
-
- OTCloseProvider(newEndpoint);
- }
- }
-
- return err;
- }
-
- ////////////////////////////////////////////////////////////
-
- void main(void)
- // The main line. This inits our connection to OpenTransport,
- // and then inits the provider factory library. It then
- // calls GetProviderFromFactory to demo the use of
- // OTTransferProviderOwnership.
- {
- OSStatus err;
-
- err = InitOpenTransport();
- if (err == noErr) {
-
- err = InitProviderFactory();
-
- if (err == noErr) {
-
- err = GetProviderFromFactory();
-
- CloseProviderFactory();
- }
-
- CloseOpenTransport();
- }
- if (err == noErr) {
- printf("Success!\n");
- } else {
- printf("Failed with error %ld.\n", err);
- }
- }